package pro.seac.twitter.web.view;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import pro.seac.twitter.application.UserManagementService;
import pro.seac.twitter.web.Navigateable;
import pro.seac.twitter.web.view.component.UserTable;

import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.VerticalLayout;

@Component
@Scope("prototype")
@Navigateable("users")
public class UsersView extends BaseView {
	private static final long serialVersionUID = 1L;
	private UserTable userTable;
	@Autowired
	private UserManagementService service;

	@Override
	public void enter(ViewChangeEvent event) {
		super.enter(event);
		refreshUsers();
	}

	@Override
	protected String getTitle() {
		return "Lista u\u017Cytkownik\u00F3w";
	}

	@Override
	protected com.vaadin.ui.Component initContent() {
		VerticalLayout container = (VerticalLayout) super.initContent();
		userTable = new UserTable();
		userTable.setSizeFull();
		container.addComponent(userTable);
		container.setExpandRatio(userTable, 1);
		container.setSizeFull();
		return container;
	}

	public void refreshUsers() {
		userTable.refreshUsers(service.getAllUserProfiles());
	}

}
